import 'package:casdon/app/config/theme/theme_extention.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';


class StatusButton extends StatelessWidget {
  /// 当前状态（true：激活状态；false：普通状态）
  final bool isActive;

  /// 激活状态下的文字
  final String activeText;

  /// 非激活状态下的文字
  final String inactiveText;

  /// 激活状态文字样式
  final TextStyle? activeTextStyle;

  /// 非激活状态文字样式
  final TextStyle? inactiveTextStyle;

  /// 激活状态背景（支持渐变色）
  final Gradient? activeGradient;

  /// 非激活状态背景（支持渐变色）
  final Gradient? inactiveGradient;

  /// 激活状态下背景色（若未设置渐变）
  final Color? activeColor;

  /// 非激活状态下背景色（若未设置渐变）
  final Color? inactiveColor;

  /// 激活状态边框颜色
  final Color? activeBorderColor;

  /// 非激活状态边框颜色
  final Color? inactiveBorderColor;

  /// 圆角
  final double borderRadius;

  /// 内边距
  final EdgeInsets? padding;

  /// 点击事件
  final VoidCallback? onTap;

  const StatusButton({
    super.key,
    this.isActive = false,
    this.activeText = '已启用',
    this.inactiveText = '启用',
    this.activeTextStyle,
    this.inactiveTextStyle,
    this.activeGradient,
    this.inactiveGradient,
    this.activeColor,
    this.inactiveColor = Colors.white,
    this.activeBorderColor,
    this.inactiveBorderColor,
    this.borderRadius = 20,
    this.padding,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    final text = isActive ? activeText : inactiveText;
    final textStyle = isActive
        ? activeTextStyle ??
              context.textTheme.bodyLarge?.copyWith(
                color: context.colorScheme.primary,
              )
        : inactiveTextStyle ??
              context.textTheme.bodyMedium?.copyWith(
                color: context.colorScheme.primary,
              );

    final borderColor = isActive
        ? (activeBorderColor ?? context.colorScheme.primary)
        : (inactiveBorderColor ?? context.customColorThemeNonNull.textColor2!);

    final backgroundColor = isActive
        ? (activeColor ?? Colors.white)
        : inactiveColor ?? Colors.white;

    final gradient = isActive ? activeGradient : inactiveGradient;

    final padding =
        this.padding ?? EdgeInsets.symmetric(horizontal: 14.w, vertical: 4.w);

    return GestureDetector(
      onTap: onTap,
      child: Container(
        padding: padding,
        decoration: BoxDecoration(
          color: gradient == null ? backgroundColor : null,
          gradient: gradient,
          border: Border.all(color: borderColor, width: 1),
          borderRadius: BorderRadius.circular(borderRadius),
        ),
        child: Text(text, style: textStyle),
      ),
    );
  }
}
